#ifndef INP_MEASUREMENTS_H
#define INP_MEASUREMENTS_H

//#include "stdafx.h"
using namespace std;
class inp_measurements 
{
	
public:

	tempmap <string,double> *ptr;
	vector <string> variables;
	time_intervall whole_time;
	string root;
	string name;
	string suffix;
	string time_horizon;
	map <string,int> CONT;

	inp_measurements(
		map<string,int> ICONT,
		vector <string> ivariables,			//vector of variables used/needed
		string intervall_mode,							//Intervallmode
		int multipli,								//multipli
		double dur,						// duration
		string itime_horizon,						// "recent" or "longterm"
		time_intervall iwhole_time,					// Intervall for which we would need the data
		string iroot,						// directory of read/write file
		string iname,						// name of read/write file
		string isuffix							// suffix of read/write file
		)
	{
		CONT=ICONT;
		variables=ivariables;
		ptr=new tempmap <string,double> (0,-999999,intervall_mode,multipli,dur);
		time_horizon=itime_horizon;
		whole_time=iwhole_time;
		root=iroot;
		name=iname;
		suffix=isuffix;
	}
	int set_input(inp_tempmap_aggr *aggr,
		const map<string,double> &plotprops)
	{
		
		
		if(CONT["READ_FROM_FILE"]!=0) //yes generate in every case new vmi data
        {
			if (set_input_from_file()){
				if (set_input_from_inp_measurements(aggr))	{
					if(set_input_from_plotprops(plotprops)) return 1;
				} // if it works 0 else 1
			}
		}
		this->ptr->print_in_file_simple_style_with_mydate(root,name,suffix);
		return 0;
	}
	int set_input_from_file()
	{
		if(this->ptr->set_read_from_file(root,name,suffix,
			ptr->intervall_mode,ptr->multipli,ptr->dur)){ 
			return 1;
		}
		return 0;
	}
	int set_input_from_inp_measurements( inp_tempmap_aggr *aggr)
	{
		if ((aggr->type_of_aggreg!="mean")&&(aggr->type_of_aggreg!="mean")) {
			err::err2("Inp_measurements::set_input_from_inp_measurements: aggr is empty");
			return 1;
		}
		if (this->ptr->set_aggregate_by_linear_interp_from_tempmap(aggr)){
			return 1;
		}
		return 0;
	}
	int set_input_from_plotprops(map <string,double> plotprops)
	{
		// Function gets measurement value of plotprops
		//inp: map<string,double> plotprops --> contains site specific variables
		//Variablename is defined in vector variables,
		//what happens if no variable id in plotprops is unknown
		timestamp start_date;
		timestamp end_date;
		time_intervall intv;
		vector <string> id;
		id=variables;
		unsigned int row;
		double mm;
		start_date.set((int)plotprops["startyear"]-1,(int)plotprops["startmon"],plotprops["startday"]);
		end_date.set((int)plotprops["endyear"],(int)plotprops["startmon"],plotprops["startday"]);
		for(row=0;row<id.size();row++){
			id[row]=name+id[row];
		}
		if(Basics_map::check_for_keys(plotprops,id)) return 1;
		// test if intv is similar to start end of tempmap
		if (!(intv.get_identity(this->whole_time))) return 1;
		// are variables empty?
		if(this->variables.size()<1) return 1;
		// set keys of tempmap
		this->ptr->set_clear();
		this->ptr->set_key(variables);
		// set  one time intervall
		this->ptr->point_time()->push_back(intv);
		// set the values
		for(row=0;row<this->variables.size();row++){
			mm=plotprops[id[row]];
			this->ptr->point_val(variables.at(row))->push_back(mm);
		}
		return 0;
	}
};
#endif